package GroupChats;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ThreadClient extends Thread{
    private Socket socket;
    public ThreadClient(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            //开始接收数据
            InputStream inputStream = socket.getInputStream();
            DataInputStream dis = new DataInputStream(inputStream);
            while (true){
                try {
                    String str = dis.readUTF();
                    System.out.println( " : " + str);
                } catch (IOException e) {
                    System.out.println(" 本机已离线!!! ");
                    dis.close();
                    socket.close();
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
